import numpy as np
import os
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D  # 空间三维画图

def showxyzc(filein):
    fi=open(filein,"r+")
    
    facex=[]
    facey=[]
    facez=[]
    facepoint=[]

    eyex=[]
    eyey=[]
    eyez=[]
    eyepoint=[]

    earx=[]
    eary=[]
    earz=[]
    earpoint=[]

    nosex=[]
    nosey=[]
    nosez=[]
    nosepoint=[]

    mousex=[]
    mousey=[]
    mousez=[]
    mousepoint=[]

    for i in range(0,11510):
        st=fi.readline()
        sp=st.split(" ")
        if (int(sp[3])==0):
            facex.append(float(sp[0]))
            facey.append(float(sp[1]))
            facez.append(float(sp[2]))
        elif (int(sp[3])==1):
            eyex.append(float(sp[0]))
            eyey.append(float(sp[1]))
            eyez.append(float(sp[2]))
        elif (int(sp[3])==2):
            nosex.append(float(sp[0]))
            nosey.append(float(sp[1]))
            nosez.append(float(sp[2]))
        elif (int(sp[3])==3):
            mousex.append(float(sp[0]))
            mousey.append(float(sp[1]))
            mousez.append(float(sp[2]))
        elif (int(sp[3])==4):
            earx.append(float(sp[0]))
            eary.append(float(sp[1]))
            earz.append(float(sp[2]))

    facepoint.append(facex)
    facepoint.append(facey)
    facepoint.append(facez)

    eyepoint.append(eyex)
    eyepoint.append(eyey)
    eyepoint.append(eyez)

    earpoint.append(earx)
    earpoint.append(eary)
    earpoint.append(earz)

    nosepoint.append(nosex)
    nosepoint.append(nosey)
    nosepoint.append(nosez)

    mousepoint.append(mousex)
    mousepoint.append(mousey)
    mousepoint.append(mousez)

    facepointp=np.array(facepoint)
    eyepointp=np.array(eyepoint)
    earpointp=np.array(earpoint)
    nosepointp=np.array(nosepoint)
    mousepointp=np.array(mousepoint)
    print(facepointp.shape)

    fig = plt.figure()
    ax = Axes3D(fig)
    ax.scatter(facepointp[0],facepointp[1],facepointp[2],c='b',label='facepoint',s=0.2)
    ax.scatter(eyepointp[0],eyepointp[1],eyepointp[2],c='m',label='facepoint',s=0.2)
    ax.scatter(earpointp[0],earpointp[1],earpointp[2],c='g',label='earpoint',s=0.2)
    ax.scatter(nosepointp[0],nosepointp[1],nosepointp[2],c='r',label='nosepoint',s=0.2)
    ax.scatter(mousepointp[0],mousepointp[1],mousepointp[2],c='k',label='mousepoint',s=0.2)

    ax.legend(loc='best')

    ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
    ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
    ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
    
    plt.show()

if __name__ == '__main__':
    showxyzc("shape_0.xyzc")